import { defineConfigWithVueTs } from '@vue/eslint-config-typescript'
import pluginVue from 'eslint-plugin-vue'
import eslintConfigPrettier from 'eslint-config-prettier'

export default defineConfigWithVueTs(
  // TypeScript声明文件特殊配置
  {
    files: ['**/*.d.ts'],
    languageOptions: {
      parser: require('@typescript-eslint/parser'),
      parserOptions: {
        project: null // 避免要求tsconfig.json
      }
    }
  },
  // 增强的Vue单文件组件配置
  {
    files: ['**/*.vue'],
    languageOptions: {
      parser: require('vue-eslint-parser'),
      parserOptions: {
        parser: require('@typescript-eslint/parser'),
        extraFileExtensions: ['.vue'],
        ecmaVersion: 'latest',
        sourceType: 'module',
        ecmaFeatures: {
          jsx: true,
          tsx: true,
          experimentalObjectRestSpread: true
        },
        project: './tsconfig.eslint.json',
        warnOnUnsupportedTypeScriptVersion: false
      }
    },
    processor: 'vue/vue3-sfc'
  },
  // TypeScript文件配置
  {
    files: ['**/*.{ts,mts,tsx}'],
    languageOptions: {
      parser: require('@typescript-eslint/parser'),
      parserOptions: {
        project: './tsconfig.eslint.json'
      }
    }
  },

  // 忽略目录配置
  {
    ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**']
  },

  // Vue 相关配置
  pluginVue.configs['flat/essential'],
  pluginVue.configs['flat/recommended'],

  // Prettier 集成配置
  {
    plugins: {
      prettier: require('eslint-plugin-prettier')
    },
    rules: {
      'prettier/prettier': 'error',
      'vue/multi-word-component-names': 'off',
      'vue/html-self-closing': 'off',
      'vue/max-attributes-per-line': 'off',
      'vue/singleline-html-element-content-newline': 'off',
      'vue/multiline-html-element-content-newline': 'off',
      '@typescript-eslint/indent': 'off'
    }
  },

  // 必须放在最后：禁用所有与 Prettier 冲突的规则
  {
    ...eslintConfigPrettier
  }
)
